/*
 * Copyright (C) 2014 Realtek Semiconductor Corp.
 * All Rights Reserved.
 *
 * This program is the proprietary software of Realtek Semiconductor
 * Corporation and/or its licensors, and only be used, duplicated,
 * modified or distributed under the authorized license from Realtek.
 *
 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 * Purpose :
 *
 * Feature : The file includes the following modules and sub-modules
 *           (1)
 */

#include "app_basic.h"
#include "feature_export_api.h"

#include "mib_table.h"
#include "omci_util.h"
#include "omci_protocol.h"



extern int MIB_TABLE_TOTAL_NUMBER;
extern omciMibTables_t gTables;
extern pthread_mutex_t gOmciTableMutex;

unsigned int me_table_sort_by_classId (va_list argp)
{     
    MIB_TABLE_T *pTable;
    MIB_TABLE_T *pNextTable;
    int i, j;
    pthread_mutex_lock(&gOmciTableMutex);
    for (i = 1; i < MIB_TABLE_TOTAL_NUMBER; i++)
    {
        for (j = 0, pTable = LIST_FIRST(&gTables.head); j < MIB_TABLE_TOTAL_NUMBER - 1; j++)
        {
            pNextTable = LIST_NEXT(pTable, entries);
            if (pTable->pTableInfo->ClassId > pNextTable->pTableInfo->ClassId)
            {
                LIST_REMOVE(pTable, entries);
                LIST_INSERT_AFTER(pNextTable, pTable, entries);
            }
            else
                pTable = pNextTable;
        }
    }
    pthread_mutex_unlock(&gOmciTableMutex);
    return FAL_OK;
}
unsigned int feature_module_init(unsigned int moduleID)
{
	FAL_ERROR_CODE	ret;

	ret = feature_api_register(
			FEATURE_API_ME_00040000, moduleID, &me_table_sort_by_classId);
	if (FAL_OK != ret)
        return FAL_FAIL;

    return FAL_OK;
}

unsigned int feature_module_exit(void)
{
	feature_api_unregister(FEATURE_API_ME_00040000);

    return FAL_OK;
}
